package kr.pe.johnkim.pushchat.mobile.controller;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatAES128;
import kr.pe.johnkim.pushchat.mobile.util.PushChatCommon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * AES-128 대칭키를 이용해서 암/복호화 하는 controller class 이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 7. 30.
 */
@Controller
@RequestMapping(value = "/pushChatAES128Controller")
public class PushChatAES128Controller {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatAES128Controller.class);

    @Autowired
    private PushChatCommon pushChatCommon;

    /**
     * AES-128 대칭키를 이용해서 문자열을 암호화해서 반환 한다.
     *
     * @param pushChatAES128
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getAes128Encode", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatAES128 getAes128Encode(@RequestBody PushChatAES128 pushChatAES128) throws Exception {
        logger.info("getAes128Encode");

        PushChatAES128 result = new PushChatAES128();
        result.setStr(this.pushChatCommon.getAes128Encode(pushChatAES128.getStr()));

        return result;
    }

    /**
     * AES-128 대칭키를 이용해서 문자열을 복호화해서 반환 한다.
     *
     * @param pushChatAES128
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getAes128Decode", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatAES128 getAes128Decode(@RequestBody PushChatAES128 pushChatAES128) throws Exception {
        logger.info("getAes128Decode");

        PushChatAES128 result = new PushChatAES128();
        result.setStr(this.pushChatCommon.getAes128Decode(pushChatAES128.getStr()));

        return result;
    }
}
